// MBDEarnIntegrateAdapter.java
package xyz.quanguanjia.masterboy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import xyz.quanguanjia.masterboy.R;

public class MBDEarnIntegrateAdapter extends RecyclerView.Adapter<MBDEarnIntegrateAdapter.EarnIntegrateViewHolder> {

    private List<String> earnIntegrationWays;
    private Context context;
    private OnEarnIntegrationClickListener listener;

    public MBDEarnIntegrateAdapter(Context context, List<String> earnIntegrationWays, OnEarnIntegrationClickListener listener) {
        this.context = context;
        this.earnIntegrationWays = earnIntegrationWays;
        this.listener = listener;
    }

    @NonNull
    @Override
    public EarnIntegrateViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_cell_earn_integrate, parent, false);
        return new EarnIntegrateViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull EarnIntegrateViewHolder holder, int position) {
        String earnIntegrationWay = earnIntegrationWays.get(position);

        // 在这里设置 ViewHolder 中的控件的数据
        holder.tvEarnIntegrationWay.setText(earnIntegrationWay);

        // 设置点击事件
        holder.layoutEarnIntegration.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 将点击事件传递到外部处理
                if (listener != null) {
                    listener.onEarnIntegrationClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return earnIntegrationWays.size();
    }

    public static class EarnIntegrateViewHolder extends RecyclerView.ViewHolder {
        TextView tvEarnIntegrationWay;
        ImageView ivRightArrow;
        LinearLayout layoutEarnIntegration;

        public EarnIntegrateViewHolder(@NonNull View itemView) {
            super(itemView);
            tvEarnIntegrationWay = itemView.findViewById(R.id.tv_earn_integration_way);
            ivRightArrow = itemView.findViewById(R.id.iv_right_arrow);
            layoutEarnIntegration = itemView.findViewById(R.id.layout_earn_integration);
        }
    }

    // 定义接口用于处理点击事件
    public interface OnEarnIntegrationClickListener {
        void onEarnIntegrationClick(int position);
    }
}
